import { createRouter, createWebHashHistory } from 'vue-router'

const Layout = () => import('@/views/Layout')
const Login = () => import('@/views/login/Login')
const Home = () => import('@/views/home/Home')
const Top = () => import('@/views/category/Top')
const Sub = () => import('@/views/category/Sub')
const Goods = () => import('@/views/goods/Goods')
const Cart = () => import('@/views/cart/Cart')

const routes = [
  {
    path: '/',
    component: Layout,
    children: [
      { path: '/', component: Home },
      { path: '/category/:id', component: Top },
      { path: '/category/sub/:id', component: Sub },
      { path: '/product/:id', component: Goods },
      { path: '/cart', component: Cart }
    ]
  },
  {
    path: '/login',
    component: Login
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes,
  // 当路由跳转时页面滚动到什么地方
  scrollBehavior () {
    return { left: 0, top: 0 }
  }
})

export default router
